<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>城市建设</title>
<%@include file="/WEB-INF/views/include/easyuifile.jsp" %>
<script language="javascript">
	function mapbuilding() {
		$.post("mapbuild.action", {
			mapid: $('#mapid').val(),
			cityid: "${cityid }",
			north: $('#north').val(),
			northwest: $('#northwest').val(),
			northeast: $('#northeast').val(),
			west: $('#west').val(),
			east: $('#east').val(),
			southwest: $('#southwest').val(),
			south: $('#south').val(),
			southeast: $('#southeast').val(),

			north_input: $('#north_input').val(),
			northwest_input: $('#northwest_input').val(),
			northeast_input: $('#northeast_input').val(),
			west_input: $('#west_input').val(),
			east_input: $('#east_input').val(),
			southwest_input: $('#southwest_input').val(),
			south_input: $('#south_input').val(),
			southeast_input: $('#southeast_input').val(),
			
			placename: $('#placename').val(),
			placedesc: $('#placedesc').val()
	    },
	    function(json) {
	        var messages = json.message;
	        if ("buildok" == messages) {
	            alert("地图建造成功。");
	            //location.href = location.href;
	            window.parent.opener.location.href = window.parent.opener.location.href;
	            window.close();
	        } else if ("usernull" == messages) {
	            alert("用户非法。");
	        } else {
	        	alert("地图建造失败。");
	        }
	    });
	}
	function change(obj) {
		if ("-1" == obj.value) {
			var inputstr = "<input id=\""+obj.id+"Input\" name=\""+obj.id+"Input\"  class='form-control'></input>";
			$("#" + obj.id).after(inputstr);
		} else {
			$("#" + obj.id + "Input").remove();
		}
	}
</script>
</head>
<body>
	<div>
		<form id="form1" method="post" action="" class="form-horizontal" role="form">
			<input type="hidden" id="id" name="id" value="${curmap.id }"/>
			<c:if test="${curmap.city != null}">
				<input type="hidden" id="city.id" name="city.id" value="${curmap.city.id }"/>
			</c:if>
			<c:if test="${curmap.city == null}">
				<div class="form-group">
					<label class="col-sm-1 control-label" for="city.id">所属城市</label>
					<div class="col-sm-3">
						<select class="form-control" id="city.id" name="city.id">
							<option value="">请选择</option>
							<option value="-1">新节点</option>
							<c:forEach items="${cities}" var="city">
								<option value="${city.id}" title="${city.citydesc}">${city.cityname }</option>
							</c:forEach>
						</select>
	               	</div>
				</div>
			</c:if>
			<div class="form-group">
               	<label class="col-sm-1 control-label" for="northwest">西北</label>
				<div class="col-sm-3">
					<select class="form-control" id="northwest" name="northwest" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.northwest == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
               	<label class="col-sm-1 control-label" for="north">北</label>
				<div class="col-sm-3">
					<select class="form-control" id="north" name="north" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.north == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
               	<label class="col-sm-1 control-label" for="northeast">东北</label>
				<div class="col-sm-3">
					<select class="form-control" id="northeast" name="northeast" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.northeast == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
            </div>
			
			<div class="form-group">
               	<label class="col-sm-1 control-label" for="west">西</label>
				<div class="col-sm-3">
					<select class="form-control" id="west" name="west" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.west == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
               	<label class="col-sm-1 control-label" for="placename">地名</label>
				<div class="col-sm-3">
					<input class="form-control" id="placename" name="placename" value="${curmap.placename }"/>
               	</div>
               	<label class="col-sm-1 control-label" for="east">东</label>
				<div class="col-sm-3">
					<select class="form-control" id="east" named="east" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.east == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
            </div>
            
			<div class="form-group">
               	<label class="col-sm-1 control-label" for="southwest">西南</label>
				<div class="col-sm-3">
					<select class="form-control" id="southwest" name="southwest" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.southwest == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
               	<label class="col-sm-1 control-label" for="south">南</label>
				<div class="col-sm-3">
					<select class="form-control" id="south" name="south" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.south == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
               	<label class="col-sm-1 control-label" for="southeast">东南</label>
				<div class="col-sm-3">
					<select class="form-control" id="southeast" name="southeast" onchange="change(this);">
						<option value="">请选择</option>
						<option value="-1">新节点</option>
						<c:forEach items="${maps}" var="map">
							<option value="${map.id}" title="${map.placedesc}"
							<c:if test="${curmap.southeast == map.id }">selected=true</c:if>
							>${map.placename }</option>
						</c:forEach>
					</select>
               	</div>
            </div>
            
			<div class="form-group">
				<label class="col-sm-1 control-label" for="placedesc">描述</label>
				<div class="col-sm-11">
					<textarea id="placedesc" name="placedesc" rows="5" class="form-control">${curmap.placedesc }</textarea>
               	</div>
            </div>
			<div class="form-group">
				<div class="col-sm-3"></div>
				<div class="col-sm-3">
					<input class="form-control" id="btnBuild" type="button" value="提交"></input>
               	</div>
				<div class="col-sm-3">
					<input class="form-control" type="reset" value="重置"></input>
				</div>
				<div class="col-sm-3"></div>
            </div>
		</form>
	</div>
	
	
</body>
<script type="text/javascript">
	//提交
	$(function(){
		$('#btnBuild').bind('click',function(){
			$("#btnBuild").attr("disabled",true);
			var formParam = $("#form1").serialize();//序列化表格内容为字符串
       	 	$.ajax({  
       	         type:'post',      
       		     url:'${ctx}/fantasy/cityBuild/editCityMap',  
       		     data:formParam,  
       		     cache:false,  
       		     success:function(data){ 
       		     	if(data.success){ 
	        		    closeCheck(data.result);
       		     	}else{
       		     		 parent.layer.msg(data.result,{icon:2,time:1000});
       		     		 $("#btnBuild").removeAttr("disabled");
       		     	}
	        	} 
       	 	});
	       	 
		});
	});

 	function closeCheck(msg){
 		parent.layer.msg(msg,{icon:1,time:1000});
	    //局部刷新
		partialRefresh();	    	 
 	}

	//一层弹出层关闭并局部刷新	
	function partialRefresh(){
		var index_ = parent.layer.getFrameIndex(window.name); //获取窗口索引
		top.mainFrame.doSearch();
		parent.layer.close(index_);
	}
</script>
</html>